
varying vec3 LightDirection;
varying vec3 EyeSpaceNormal;
varying vec4 LightDiffuseColor;
varying vec4 VertexColor;
varying vec2 fs_TexCoords;

// preferez une variable uniforme
// les objets ne pourront etre plus sombre que la valeur de ambient si ils sont eloignees de la light
const vec3 ambient = vec3(0.1, 0.1, 0.1);

uniform sampler2D Texture0;

void main()
{	
	vec3 N = normalize(EyeSpaceNormal);
	vec3 L = normalize(LightDirection);

	float NdotL = max(0.0, dot(N, L));

	vec4 TexColor = texture2D(Texture0, fs_TexCoords);

	vec4 FinalLightColor = vec4( max(ambient, NdotL * VertexColor.rgb * LightDiffuseColor.rgb), 1.0 );
	
	gl_FragColor = TexColor * FinalLightColor;
}